#pragma once

#include "new.h"

//sdl is used to create the window and render the pictures
#include "SDL.h"

/*Class to handle the display of the generated images.	*/
/*This class is a singleton and should be accessed		*/
/*using the VISU macro.									*/			
class CVisualisation
{

private:
	//unique instance of CVisualisation class
	static CVisualisation* m_instance; 

	//window width
	unsigned int m_width;

	//window height
	unsigned int m_height;

	//bits per pixel
	unsigned int m_bpp;

	//screen buffer
	char* m_screenBuffer;

	//screen buffer with reversed line
	char* m_reverseScreenBuffer; 

	//sdl surface object used as interface for the screen buffer to access the window
	SDL_Surface* m_surfaceScreenBuffer;

	//sdl surface representing the window
	SDL_Surface* m_window;

	//sdl surface object for the reversed screen buffer used to save into BMP file
	SDL_Surface* m_surfaceReversedScreenBuffer;

private:
	//Constructor
	CVisualisation(void);

	//Destructor
	~CVisualisation(void);

public:
	//return the unique instance of the CVisualisation class
	static CVisualisation& getInstance();

	//delete the singleton
	void close();

	//initialise the window
	bool init(unsigned int width, unsigned int height, unsigned int bpp);

	//create the reverse screen buffer from the current screen buffer
	bool createReverseScreenBuffer();

	//prepare sdl to render
	void preRender();

	//render on the screen
	void doRender();

	//refresh window
	void postRender();

	//get a pointer to the screen buffer
	char* getScreenBuffer() const;

	//get a pointer to the reverse screen buffer
	char* getReverseScreenBuffer() const;

	//save the current screen buffer into a bmp file
	bool saveScreenBufferToBMP(const char* filename)const;

	//save the current reversed screen buffer into a bmp file (update the reversed screen buffer first)
	bool saveReversedScreenBufferToBMP(const char* filename)const;
};

//macro used to access the Visualisation singleton
#define VISU CVisualisation::getInstance()

